
export const group1 = {
  data(){
    return {
      status: 'loadmore', //加载的状态
      iconType: 'flower', //加载图标样式
      isLoading: false, //是否要加载数据
      pageNo: 1,//第几页
      list: [],//群团列表数据
    }
  },
  onLoad(){
    this.getList()
  },
  onShow() {

    uni.$on('press',d=>{
      if(d){
        this.getList()
      }
    })
  },
  methods:{
    async loadmore(){
      // 每次出发该方法，都要使页数加一
      this.pageNo++
      await this.getList()
    },
    //重置
    onRest(type=0){
      this.pageNo= 1
      this.status='loadmore'
      this.iconType='flower'
      this.isLoading=false
      this.list = []
    },
    //群团列表
    async  getLists(cb,params,type) {
      if (this.isLoading) {
        return
      }
      this.isLoading = true
      this.status = 'loading'
      const {
        code,
        result: { records: list, total },
      } = await cb(params)
      if (code === 200) {
        this.isLoading = false
        uni.hideLoading()
        if (!list.length) {
          this.status = 'nomore'
        } else {
          this.status = 'loadmore'
          this.list = [...this.list, ...list]
          if(type==='1'){
            this.$forceUpdate()
          }
          if (this.list.length >= total) {
            this.status = 'nomore'
          }
        }
      } else {
        this.status = 'nomore'
      }
    },
  },
  //加载到底部进行请求新的数据
  onReachBottom() {
    if (this.status === 'loadmore') {
      this.loadmore()
    }
  },
}
